<?php
/**
 * Created by PhpStorm.
 * User: 94004
 * Date: 2017/12/31
 * Time: 14:20
 */
header("Content-Type:text/html;charset=utf-8;");
require_once "../util/db_helper.php";
$id = $_POST["id"];
$sql = " SELECT * FROM options o WHERE o.`key`='nav_menus' ";
$res = query($sql);
$dataRes = $res[0]["value"];
$data = json_decode($dataRes);
foreach ($data as $key => $value) {
    if ($value->id == $id) {
        array_splice($data, $key, 1);
        break;
    }
}
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
$updateSql = "UPDATE options o SET o.value='{$json}' WHERE o.`key` = 'nav_menus'";
$updateRes = execute($updateSql);
$arr = array("code" => 101, "msg" => "导航链接删除失败");
if ($updateRes) {
    $arr["code"] = 100;
    $arr["msg"] = "导航链接删除成功";
}
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
?>